﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletPrefab : MonoBehaviour
{
    Tank owner;
    public float bulletSpeed = 20;
    public void Fire(Tank owner)
    {
        this.owner = owner;
        GetComponent<Rigidbody>().velocity = transform.forward * bulletSpeed;
    }
    // Use this for initialization
    void Start()
    {

    }
    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Tank"))
        {
           Tank tank= other.GetComponent<Tank>();
            if (tank!=owner)
            {
                //本机玩家的子弹才需要发送消息
                if (ActorManager.Instance.IsLocalUser(owner.Account.username))
                {
                   tank.OnDamage(owner);
                }                
                Destroy(this.gameObject);
            }
        }
        else
        {
            Destroy(this.gameObject);
        }
    }
}
